<?php
	class Payment extends CI_Controller
	{
		public function __construct()
		{
			parent::__construct();
			if (!isset($_SESSION)) {
			    session_start();
			    session_regenerate_id();
			}
			$this->load->helper("url");
			
		}
		public function index()
		{
			$id_city=0;
			if(isset($_SESSION['accountdeal'])){
				$mang=$_SESSION['accountdeal'];
				$id_city=$mang[6];
			}
			$data=array();
			$this->load->model("mcategory");
			$data['list_category']=$this->mcategory->list_category();
			
			$this->load->model("mdeal");
			$data['list_deal_today']=$this->mdeal->list_deal_today();
			
			$this->load->model("mpayment");
			$data['list_city']=$this->mpayment->list_city();
			$data['list_district']=$this->mpayment->list_district_city($id_city);
			
			$data['action']="payment";
			$this->load->view("main_template", $data);
		}
		public function save_order()
		{
			
			if(isset($_SESSION['accountdeal'])){
				$mang=$_SESSION['accountdeal'];
			}
			
			$custommer=$_REQUEST['custommer'];
			$phone=$_REQUEST['phone'];
			$email=$_REQUEST['email'];
			$address=$_REQUEST['address'];
			$city=$_REQUEST['city'];
			$district=$_REQUEST['district'];
			$memo=$_REQUEST['memo'];
			$PayMenthod=$_REQUEST['PayMenthod'];
			
			$this->load->model("mpayment");
			$data=$this->mpayment->save_order($custommer,$phone,$email,$address,$city,$district,$memo,$PayMenthod,$mang[0]);
		}
		public function changecity()
		{
			$id_city=$_REQUEST['id_city'];
			$this->load->model("mpayment");
			$data=$this->mpayment->list_district_city($id_city);
			$body='<select style="width: 200px; height:24px; border:#ccc solid 1px;" name="district" id="district">
              <option value="0" selected="selected">Chọn Quận Huyện</option>';
			foreach ($data as $value =>$giatri){
				$body.='<option value="'.$giatri['id'].'" >'.$giatri['name'].'</option>';
			}
            $body.='</select>';
			echo $body;
		}
		public function thanks()
		{
			$data=array();
			$this->load->model("mcategory");
			$data['list_category']=$this->mcategory->list_category();
			
			$this->load->model("mdeal");
			$data['list_deal_today']=$this->mdeal->list_deal_today();
			
			
			
			$data['action']="thanks";
			$this->load->view("main_template", $data);
		}
	}
?>